package com.lhj.message.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.PartitionOffset;
import org.springframework.kafka.annotation.TopicPartition;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author lhj
 * @Date 2024/8/13 17:05
 */
@Slf4j
@Component
public class Consumer {
    
    @KafkaListener(id = "foo", topics = "news_1001")
    public void listenerNews1001(String data) {
        log.info("news_1001 data:{}", data);
        
        //ConsumerRecord record
       /* Object key = record.key();
        Object value = record.value();
        log.info("news_1001 key:{}, value:{}", key, value);*/
    }
    
    @KafkaListener(groupId = "orderGroup", topicPartitions = {
            @TopicPartition(topic = "order", partitionOffsets = {
                    @PartitionOffset(partition = "0", initialOffset = "0")
            })
    })
    public void listenerOrder(ConsumerRecord record) {
        Object key = record.key();
        Object value = record.value();
        log.info("order key:{}, value:{}", key, value);

    }
    
    
    
}
